<template>
  <div class="p-6 space-y-6">
    <!-- 页面标题 -->
    <div class="text-center mb-8">
      <h1 class="text-3xl font-bold text-white mb-2 animate-glow">{{ t('policyMatch') }}</h1>
      <p class="text-electric-500">{{ t('intelligentPolicyEnterpriseMatchingSystem') }}</p>
    </div>

    <!-- 功能选择标签页 -->
    <div class="flex space-x-1 glass-card p-1 rounded-xl">
      <button
        @click="activeTab = 'policy-to-enterprise'"
        :class="[
          'flex-1 py-3 px-6 rounded-lg transition-all duration-200 font-medium',
          activeTab === 'policy-to-enterprise'
            ? 'bg-electric-500 text-cyber-50'
            : 'text-white/70 hover:text-white hover:bg-white/10'
        ]"
      >
        政策匹配企业
      </button>
      <button
        @click="activeTab = 'enterprise-to-policy'"
        :class="[
          'flex-1 py-3 px-6 rounded-lg transition-all duration-200 font-medium',
          activeTab === 'enterprise-to-policy'
            ? 'bg-electric-500 text-cyber-50'
            : 'text-white/70 hover:text-white hover:bg-white/10'
        ]"
      >
        企业匹配政策
      </button>
    </div>

    <!-- 政策匹配企业标签页 -->
    <div v-if="activeTab === 'policy-to-enterprise'" class="space-y-6">
      <div class="grid grid-cols-1 xl:grid-cols-3 gap-6">
        <!-- 政策选择 -->
        <div class="glass-card p-6">
          <h3 class="text-xl font-semibold text-white mb-4 flex items-center">
            <FileText class="w-5 h-5 mr-2 text-tech-blue-400" />
            选择政策
          </h3>
          
          <div class="space-y-4">
            <div class="relative">
              <Search class="absolute left-3 top-1/2 transform -translate-y-1/2 text-electric-500 w-4 h-4" />
              <input
                v-model="policySearchQuery"
                type="text"
                placeholder="搜索政策..."
                class="w-full pl-10 pr-4 py-2 cyber-input text-sm"
              />
            </div>

            <div class="space-y-2 max-h-96 overflow-y-auto">
              <div
                v-for="policy in filteredPolicies"
                :key="policy.id"
                @click="selectPolicy(policy)"
                :class="[
                  'p-3 rounded-lg border-2 cursor-pointer transition-all duration-200',
                  selectedPolicy?.id === policy.id 
                    ? 'border-electric-500 bg-electric-500/20' 
                    : 'border-white/20 hover:border-white/40'
                ]"
              >
                <h4 class="text-white font-medium text-sm">{{ policy.title }}</h4>
                <p class="text-white/70 text-xs mt-1">{{ policy.department }}</p>
                <div class="flex items-center space-x-2 mt-2">
                  <span class="px-2 py-1 bg-tech-blue-500/20 text-tech-blue-300 rounded text-xs">
                    {{ policy.category }}
                  </span>
                  <span class="px-2 py-1 bg-green-500/20 text-green-300 rounded text-xs">
                    {{ policy.status }}
                  </span>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 匹配条件设置 -->
        <div class="glass-card p-6">
          <h3 class="text-xl font-semibold text-white mb-4 flex items-center">
            <Settings class="w-5 h-5 mr-2 text-electric-500" />
            匹配条件
          </h3>
          
          <div class="space-y-4">
            <div>
              <label class="block text-white text-sm font-medium mb-2">企业规模</label>
              <select v-model="matchFilters.companySize" class="cyber-input text-sm">
                <option value="">不限</option>
                <option value="大型企业">大型企业</option>
                <option value="中型企业">中型企业</option>
                <option value="小型企业">小型企业</option>
                <option value="微型企业">微型企业</option>
              </select>
            </div>

            <div>
              <label class="block text-white text-sm font-medium mb-2">行业类型</label>
              <select v-model="matchFilters.industry" class="cyber-input text-sm">
                <option value="">不限</option>
                <option value="制造业">制造业</option>
                <option value="信息技术">信息技术</option>
                <option value="金融业">金融业</option>
                <option value="服务业">服务业</option>
                <option value="建筑业">建筑业</option>
              </select>
            </div>

            <div>
              <label class="block text-white text-sm font-medium mb-2">地区范围</label>
              <select v-model="matchFilters.region" class="cyber-input text-sm">
                <option value="">不限</option>
                <option value="北京">北京</option>
                <option value="上海">上海</option>
                <option value="广东">广东</option>
                <option value="江苏">江苏</option>
                <option value="浙江">浙江</option>
              </select>
            </div>

            <div>
              <label class="block text-white text-sm font-medium mb-2">匹配度阈值</label>
              <div class="flex items-center space-x-3">
                <input
                  v-model="matchFilters.threshold"
                  type="range"
                  min="50"
                  max="100"
                  class="flex-1"
                />
                <span class="text-white text-sm min-w-[3rem]">{{ matchFilters.threshold }}%</span>
              </div>
            </div>

            <button
              @click="performPolicyMatch"
              :disabled="!selectedPolicy"
              class="w-full cyber-button flex items-center justify-center space-x-2"
            >
              <Target class="w-4 h-4" />
              <span>开始匹配</span>
            </button>
          </div>
        </div>

        <!-- 匹配结果预览 -->
        <div class="glass-card p-6">
          <h3 class="text-xl font-semibold text-white mb-4 flex items-center">
            <TrendingUp class="w-5 h-5 mr-2 text-green-400" />
            匹配统计
          </h3>
          
          <div class="space-y-4">
            <div class="text-center p-4 bg-white/5 rounded-lg">
              <div class="text-3xl font-bold text-electric-500">{{ matchResults.length }}</div>
              <div class="text-white/70 text-sm">匹配企业数</div>
            </div>

            <div class="grid grid-cols-2 gap-4 text-sm">
              <div class="text-center p-3 bg-white/5 rounded-lg">
                <div class="text-lg font-semibold text-green-400">{{ highMatchCount }}</div>
                <div class="text-white/70">高匹配度</div>
              </div>
              <div class="text-center p-3 bg-white/5 rounded-lg">
                <div class="text-lg font-semibold text-yellow-400">{{ mediumMatchCount }}</div>
                <div class="text-white/70">中匹配度</div>
              </div>
            </div>

            <div class="p-3 bg-white/5 rounded-lg">
              <h4 class="text-white font-medium text-sm mb-2">匹配分布</h4>
              <div class="space-y-2">
                <div class="flex justify-between text-xs">
                  <span class="text-white/70">制造业</span>
                  <span class="text-white">35%</span>
                </div>
                <div class="flex justify-between text-xs">
                  <span class="text-white/70">信息技术</span>
                  <span class="text-white">28%</span>
                </div>
                <div class="flex justify-between text-xs">
                  <span class="text-white/70">服务业</span>
                  <span class="text-white">22%</span>
                </div>
                <div class="flex justify-between text-xs">
                  <span class="text-white/70">其他</span>
                  <span class="text-white">15%</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 匹配结果列表 -->
      <div class="glass-card p-6">
        <div class="flex items-center justify-between mb-6">
          <h3 class="text-xl font-semibold text-white flex items-center">
            <Building class="w-5 h-5 mr-2 text-yellow-400" />
            匹配企业列表
          </h3>
          <div class="flex items-center space-x-4">
            <span class="text-white/70 text-sm">排序方式：</span>
            <select v-model="sortBy" class="cyber-input py-1 text-sm">
              <option value="match">匹配度</option>
              <option value="size">企业规模</option>
              <option value="industry">行业类型</option>
            </select>
          </div>
        </div>

        <div v-if="matchResults.length > 0" class="space-y-4">
          <div
            v-for="result in sortedMatchResults"
            :key="result.enterprise.id"
            class="border border-white/20 rounded-lg p-4 hover:border-electric-500/50 transition-colors"
          >
            <div class="flex items-start justify-between">
              <div class="flex-1">
                <div class="flex items-center space-x-3 mb-2">
                  <h4 class="text-lg font-semibold text-white">{{ result.enterprise.name }}</h4>
                  <span :class="getMatchLevelClass(result.matchScore)">
                    {{ result.matchScore }}% 匹配
                  </span>
                </div>
                
                <div class="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm text-white/70 mb-3">
                  <div class="flex items-center space-x-1">
                    <Building class="w-3 h-3" />
                    <span>{{ result.enterprise.size }}</span>
                  </div>
                  <div class="flex items-center space-x-1">
                    <Tag class="w-3 h-3" />
                    <span>{{ result.enterprise.industry }}</span>
                  </div>
                  <div class="flex items-center space-x-1">
                    <MapPin class="w-3 h-3" />
                    <span>{{ result.enterprise.location }}</span>
                  </div>
                  <div class="flex items-center space-x-1">
                    <Calendar class="w-3 h-3" />
                    <span>成立{{ result.enterprise.establishedYear }}年</span>
                  </div>
                </div>

                <p class="text-white/80 text-sm mb-3">{{ result.enterprise.description }}</p>

                <div class="flex items-center space-x-4 text-sm">
                  <div class="flex items-center space-x-2">
                    <span class="text-white/70">匹配原因：</span>
                    <div class="flex flex-wrap gap-1">
                      <span
                        v-for="reason in result.matchReasons"
                        :key="reason"
                        class="px-2 py-1 bg-green-500/20 text-green-300 rounded text-xs"
                      >
                        {{ reason }}
                      </span>
                    </div>
                  </div>
                </div>
              </div>

              <div class="flex flex-col space-y-2">
                <button class="cyber-button text-sm px-4 py-2">
                  查看详情
                </button>
                <button class="bg-electric-500 hover:bg-electric-600 text-cyber-50 px-4 py-2 rounded-lg transition-colors text-sm">
                  推送政策
                </button>
              </div>
            </div>
          </div>
        </div>

        <div v-else class="text-center py-12">
          <Target class="w-16 h-16 text-electric-500 mx-auto mb-4" />
          <p class="text-white/70 mb-2">暂无匹配结果</p>
          <p class="text-white/50 text-sm">请选择政策并设置匹配条件</p>
        </div>
      </div>
    </div>

    <!-- 企业匹配政策标签页 -->
    <div v-if="activeTab === 'enterprise-to-policy'" class="space-y-6">
      <div class="grid grid-cols-1 xl:grid-cols-3 gap-6">
        <!-- 企业信息输入 -->
        <div class="glass-card p-6">
          <h3 class="text-xl font-semibold text-white mb-4 flex items-center">
            <Building class="w-5 h-5 mr-2 text-tech-blue-400" />
            企业信息
          </h3>
          
          <div class="space-y-4">
            <div>
              <label class="block text-white text-sm font-medium mb-2">企业名称</label>
              <input
                v-model="enterpriseInfo.name"
                type="text"
                placeholder="输入企业名称..."
                class="cyber-input text-sm"
              />
            </div>

            <div>
              <label class="block text-white text-sm font-medium mb-2">企业规模</label>
              <select v-model="enterpriseInfo.size" class="cyber-input text-sm">
                <option value="">请选择</option>
                <option value="大型企业">大型企业</option>
                <option value="中型企业">中型企业</option>
                <option value="小型企业">小型企业</option>
                <option value="微型企业">微型企业</option>
              </select>
            </div>

            <div>
              <label class="block text-white text-sm font-medium mb-2">行业类型</label>
              <select v-model="enterpriseInfo.industry" class="cyber-input text-sm">
                <option value="">请选择</option>
                <option value="制造业">制造业</option>
                <option value="信息技术">信息技术</option>
                <option value="金融业">金融业</option>
                <option value="服务业">服务业</option>
                <option value="建筑业">建筑业</option>
              </select>
            </div>

            <div>
              <label class="block text-white text-sm font-medium mb-2">所在地区</label>
              <select v-model="enterpriseInfo.location" class="cyber-input text-sm">
                <option value="">请选择</option>
                <option value="北京">北京</option>
                <option value="上海">上海</option>
                <option value="广东">广东</option>
                <option value="江苏">江苏</option>
                <option value="浙江">浙江</option>
              </select>
            </div>

            <div>
              <label class="block text-white text-sm font-medium mb-2">年营业额（万元）</label>
              <input
                v-model="enterpriseInfo.revenue"
                type="number"
                placeholder="输入年营业额..."
                class="cyber-input text-sm"
              />
            </div>

            <div>
              <label class="block text-white text-sm font-medium mb-2">员工人数</label>
              <input
                v-model="enterpriseInfo.employees"
                type="number"
                placeholder="输入员工人数..."
                class="cyber-input text-sm"
              />
            </div>
          </div>
        </div>

        <!-- 匹配偏好设置 -->
        <div class="glass-card p-6">
          <h3 class="text-xl font-semibold text-white mb-4 flex items-center">
            <Settings class="w-5 h-5 mr-2 text-electric-500" />
            匹配偏好
          </h3>
          
          <div class="space-y-4">
            <div>
              <label class="block text-white text-sm font-medium mb-2">关注政策类型</label>
              <div class="space-y-2">
                <label
                  v-for="category in policyCategories"
                  :key="category"
                  class="flex items-center space-x-2 cursor-pointer"
                >
                  <input
                    type="checkbox"
                    :value="category"
                    v-model="enterprisePreferences.categories"
                    class="w-4 h-4 text-electric-500"
                  />
                  <span class="text-white text-sm">{{ category }}</span>
                </label>
              </div>
            </div>

            <div>
              <label class="block text-white text-sm font-medium mb-2">优惠类型偏好</label>
              <div class="space-y-2">
                <label
                  v-for="benefit in benefitTypes"
                  :key="benefit"
                  class="flex items-center space-x-2 cursor-pointer"
                >
                  <input
                    type="checkbox"
                    :value="benefit"
                    v-model="enterprisePreferences.benefits"
                    class="w-4 h-4 text-electric-500"
                  />
                  <span class="text-white text-sm">{{ benefit }}</span>
                </label>
              </div>
            </div>

            <div>
              <label class="block text-white text-sm font-medium mb-2">申请难度偏好</label>
              <select v-model="enterprisePreferences.difficulty" class="cyber-input text-sm">
                <option value="">不限</option>
                <option value="简单">简单申请</option>
                <option value="中等">中等难度</option>
                <option value="复杂">不限难度</option>
              </select>
            </div>

            <button
              @click="performEnterpriseMatch"
              :disabled="!isEnterpriseInfoComplete"
              class="w-full cyber-button flex items-center justify-center space-x-2"
            >
              <Search class="w-4 h-4" />
              <span>智能匹配</span>
            </button>
          </div>
        </div>

        <!-- 匹配政策预览 -->
        <div class="glass-card p-6">
          <h3 class="text-xl font-semibold text-white mb-4 flex items-center">
            <BarChart class="w-5 h-5 mr-2 text-green-400" />
            匹配概览
          </h3>
          
          <div class="space-y-4">
            <div class="text-center p-4 bg-white/5 rounded-lg">
              <div class="text-3xl font-bold text-electric-500">{{ policyMatches.length }}</div>
              <div class="text-white/70 text-sm">匹配政策数</div>
            </div>

            <div class="grid grid-cols-1 gap-4 text-sm">
              <div class="p-3 bg-white/5 rounded-lg">
                <div class="flex justify-between items-center mb-2">
                  <span class="text-white/70">高匹配度</span>
                  <span class="text-green-400 font-semibold">{{ highPolicyMatchCount }}</span>
                </div>
                <div class="w-full bg-white/20 rounded-full h-1">
                  <div 
                    class="bg-green-400 h-1 rounded-full"
                    :style="{ width: (highPolicyMatchCount / policyMatches.length * 100) + '%' }"
                  ></div>
                </div>
              </div>

              <div class="p-3 bg-white/5 rounded-lg">
                <div class="flex justify-between items-center mb-2">
                  <span class="text-white/70">中匹配度</span>
                  <span class="text-yellow-400 font-semibold">{{ mediumPolicyMatchCount }}</span>
                </div>
                <div class="w-full bg-white/20 rounded-full h-1">
                  <div 
                    class="bg-yellow-400 h-1 rounded-full"
                    :style="{ width: (mediumPolicyMatchCount / policyMatches.length * 100) + '%' }"
                  ></div>
                </div>
              </div>
            </div>

            <div class="p-3 bg-white/5 rounded-lg">
              <h4 class="text-white font-medium text-sm mb-2">预计收益</h4>
              <div class="text-center">
                <div class="text-xl font-bold text-electric-500">≈ 156万元</div>
                <div class="text-white/70 text-xs">年度优惠总额</div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 匹配政策列表 -->
      <div class="glass-card p-6">
        <div class="flex items-center justify-between mb-6">
          <h3 class="text-xl font-semibold text-white flex items-center">
            <FileText class="w-5 h-5 mr-2 text-yellow-400" />
            推荐政策列表
          </h3>
          <div class="flex items-center space-x-4">
            <span class="text-white/70 text-sm">排序方式：</span>
            <select v-model="policySortBy" class="cyber-input py-1 text-sm">
              <option value="match">匹配度</option>
              <option value="benefit">优惠力度</option>
              <option value="difficulty">申请难度</option>
            </select>
          </div>
        </div>

        <div v-if="policyMatches.length > 0" class="space-y-4">
          <div
            v-for="match in sortedPolicyMatches"
            :key="match.policy.id"
            class="border border-white/20 rounded-lg p-4 hover:border-electric-500/50 transition-colors"
          >
            <div class="flex items-start justify-between">
              <div class="flex-1">
                <div class="flex items-center space-x-3 mb-2">
                  <h4 class="text-lg font-semibold text-white">{{ match.policy.title }}</h4>
                  <span :class="getMatchLevelClass(match.matchScore)">
                    {{ match.matchScore }}% 匹配
                  </span>
                  <span class="px-2 py-1 bg-green-500/20 text-green-300 rounded text-xs">
                    预计收益: {{ match.expectedBenefit }}万元
                  </span>
                </div>
                
                <div class="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm text-white/70 mb-3">
                  <div class="flex items-center space-x-1">
                    <Building class="w-3 h-3" />
                    <span>{{ match.policy.department }}</span>
                  </div>
                  <div class="flex items-center space-x-1">
                    <Tag class="w-3 h-3" />
                    <span>{{ match.policy.category }}</span>
                  </div>
                  <div class="flex items-center space-x-1">
                    <Clock class="w-3 h-3" />
                    <span>申请{{ match.applicationDifficulty }}</span>
                  </div>
                  <div class="flex items-center space-x-1">
                    <Calendar class="w-3 h-3" />
                    <span>{{ match.policy.deadline || '长期有效' }}</span>
                  </div>
                </div>

                <p class="text-white/80 text-sm mb-3">{{ match.policy.summary }}</p>

                <div class="flex items-center space-x-4 text-sm">
                  <div class="flex items-center space-x-2">
                    <span class="text-white/70">匹配关键点：</span>
                    <div class="flex flex-wrap gap-1">
                      <span
                        v-for="point in match.matchPoints"
                        :key="point"
                        class="px-2 py-1 bg-blue-500/20 text-blue-300 rounded text-xs"
                      >
                        {{ point }}
                      </span>
                    </div>
                  </div>
                </div>
              </div>

              <div class="flex flex-col space-y-2">
                <button class="cyber-button text-sm px-4 py-2">
                  查看详情
                </button>
                <button class="bg-electric-500 hover:bg-electric-600 text-cyber-50 px-4 py-2 rounded-lg transition-colors text-sm">
                  申请指导
                </button>
              </div>
            </div>
          </div>
        </div>

        <div v-else class="text-center py-12">
          <Search class="w-16 h-16 text-electric-500 mx-auto mb-4" />
          <p class="text-white/70 mb-2">暂无匹配政策</p>
          <p class="text-white/50 text-sm">请完善企业信息并进行匹配</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { 
  FileText, 
  Search, 
  Settings,
  Target,
  TrendingUp,
  Building,
  Tag,
  MapPin,
  Calendar,
  BarChart,
  Clock
} from 'lucide-vue-next'

export default {
  name: 'PolicyMatch',
  components: {
    FileText,
    Search,
    Settings,
    Target,
    TrendingUp,
    Building,
    Tag,
    MapPin,
    Calendar,
    BarChart,
    Clock
  },
  inject: ['globalState'],
  computed: {
    currentLanguage() {
      return this.globalState.currentLanguage
    },
    translations() {
      return {
        zh: {
          policyMatch: '政策匹配',
          intelligentPolicyEnterpriseMatchingSystem: '智能政策企业双向匹配系统'
        },
        en: {
          policyMatch: 'Policy Match',
          intelligentPolicyEnterpriseMatchingSystem: 'Intelligent Policy-Enterprise Bidirectional Matching System'
        }
      }
    },
    filteredPolicies() {
      return this.policies.filter(policy => {
        if (!this.policySearchQuery) return true
        return policy.title.toLowerCase().includes(this.policySearchQuery.toLowerCase()) ||
               policy.department.toLowerCase().includes(this.policySearchQuery.toLowerCase())
      })
    },
    
    highMatchCount() {
      return this.matchResults.filter(r => r.matchScore >= 80).length
    },
    
    mediumMatchCount() {
      return this.matchResults.filter(r => r.matchScore >= 60 && r.matchScore < 80).length
    },
    
    sortedMatchResults() {
      return [...this.matchResults].sort((a, b) => {
        switch (this.sortBy) {
          case 'match':
            return b.matchScore - a.matchScore
          case 'size':
            return this.getSizeValue(b.enterprise.size) - this.getSizeValue(a.enterprise.size)
          case 'industry':
            return a.enterprise.industry.localeCompare(b.enterprise.industry)
          default:
            return 0
        }
      })
    },
    
    isEnterpriseInfoComplete() {
      return this.enterpriseInfo.name && 
             this.enterpriseInfo.size && 
             this.enterpriseInfo.industry && 
             this.enterpriseInfo.location
    },
    
    highPolicyMatchCount() {
      return this.policyMatches.filter(m => m.matchScore >= 80).length
    },
    
    mediumPolicyMatchCount() {
      return this.policyMatches.filter(m => m.matchScore >= 60 && m.matchScore < 80).length
    },
    
    sortedPolicyMatches() {
      return [...this.policyMatches].sort((a, b) => {
        switch (this.policySortBy) {
          case 'match':
            return b.matchScore - a.matchScore
          case 'benefit':
            return b.expectedBenefit - a.expectedBenefit
          case 'difficulty':
            return this.getDifficultyValue(a.applicationDifficulty) - this.getDifficultyValue(b.applicationDifficulty)
          default:
            return 0
        }
      })
    }
  },
  data() {
    return {
      activeTab: 'policy-to-enterprise',
      
      // 政策匹配企业相关数据
      policySearchQuery: '',
      selectedPolicy: null,
      matchFilters: {
        companySize: '',
        industry: '',
        region: '',
        threshold: 70
      },
      sortBy: 'match',
      matchResults: [],
      
      // 企业匹配政策相关数据
      enterpriseInfo: {
        name: '',
        size: '',
        industry: '',
        location: '',
        revenue: '',
        employees: ''
      },
      enterprisePreferences: {
        categories: [],
        benefits: [],
        difficulty: ''
      },
      policySortBy: 'match',
      policyMatches: [],
      
      // 基础数据
      policies: [
        {
          id: 1,
          title: '关于支持小微企业发展的若干措施',
          department: '财政部',
          category: '财税政策',
          status: '生效中',
          summary: '为进一步支持小微企业发展，减轻企业负担，促进就业稳定，制定本措施。',
          deadline: '2024-12-31'
        },
        {
          id: 2,
          title: '数字化转型专项扶持政策',
          department: '工信部',
          category: '产业政策',
          status: '生效中',
          summary: '加快推进制造业数字化转型，提升企业竞争力，特制定专项扶持政策。',
          deadline: '2024-06-30'
        },
        {
          id: 3,
          title: '高新技术企业认定管理办法',
          department: '科技部',
          category: '科技政策',
          status: '生效中',
          summary: '完善高新技术企业认定和管理工作，促进高新技术产业发展。',
          deadline: null
        },
        {
          id: 4,
          title: '绿色金融发展指导意见',
          department: '央行',
          category: '金融政策',
          status: '即将生效',
          summary: '为推动绿色金融体系建设，引导金融资源向绿色领域配置。',
          deadline: '2024-09-30'
        }
      ],
      
      enterprises: [
        {
          id: 1,
          name: '创新科技有限公司',
          size: '小型企业',
          industry: '信息技术',
          location: '北京',
          establishedYear: 2018,
          description: '专注于人工智能和大数据技术研发，拥有多项自主知识产权。',
          employees: 85,
          revenue: 2800
        },
        {
          id: 2,
          name: '绿色制造集团',
          size: '大型企业',
          industry: '制造业',
          location: '江苏',
          establishedYear: 2005,
          description: '致力于环保制造技术，是行业内数字化转型的先行者。',
          employees: 1200,
          revenue: 58000
        },
        {
          id: 3,
          name: '微创服务公司',
          size: '微型企业',
          industry: '服务业',
          location: '上海',
          establishedYear: 2020,
          description: '新兴的互联网服务企业，专注于为小微企业提供数字化解决方案。',
          employees: 12,
          revenue: 150
        }
      ],
      
      policyCategories: ['财税政策', '产业政策', '金融政策', '科技政策', '环保政策', '就业政策'],
      benefitTypes: ['税收减免', '资金补贴', '贷款优惠', '场地支持', '人才政策', '技术扶持']
    }
  },
  
  methods: {
    t(key, params = {}) {
      let text = this.translations[this.currentLanguage.value || this.currentLanguage][key] || key
      Object.keys(params).forEach(param => {
        text = text.replace(`{${param}}`, params[param])
      })
      return text
    },
    
    selectPolicy(policy) {
      this.selectedPolicy = policy
    },
    
    performPolicyMatch() {
      if (!this.selectedPolicy) return
      
      // 模拟政策匹配企业的逻辑
      const matchedEnterprises = this.enterprises.map(enterprise => {
        const matchScore = this.calculatePolicyMatchScore(this.selectedPolicy, enterprise)
        
        if (matchScore < this.matchFilters.threshold) return null
        
        return {
          enterprise,
          matchScore,
          matchReasons: this.getPolicyMatchReasons(this.selectedPolicy, enterprise)
        }
      }).filter(Boolean)
      
      this.matchResults = matchedEnterprises
    },
    
    performEnterpriseMatch() {
      if (!this.isEnterpriseInfoComplete) return
      
      // 模拟企业匹配政策的逻辑
      const matchedPolicies = this.policies.map(policy => {
        const matchScore = this.calculateEnterpriseMatchScore(this.enterpriseInfo, policy)
        
        if (matchScore < 50) return null
        
        return {
          policy,
          matchScore,
          expectedBenefit: this.calculateExpectedBenefit(this.enterpriseInfo, policy),
          applicationDifficulty: this.getApplicationDifficulty(policy),
          matchPoints: this.getEnterpriseMatchPoints(this.enterpriseInfo, policy)
        }
      }).filter(Boolean)
      
      this.policyMatches = matchedPolicies
    },
    
    calculatePolicyMatchScore(policy, enterprise) {
      let score = 50 // 基础分
      
      // 根据企业规模匹配
      if (policy.category === '财税政策' && enterprise.size.includes('小')) {
        score += 20
      }
      
      // 根据行业匹配
      if (policy.category === '产业政策' && enterprise.industry === '制造业') {
        score += 25
      }
      
      if (policy.category === '科技政策' && enterprise.industry === '信息技术') {
        score += 25
      }
      
      // 随机因素模拟其他匹配条件
      score += Math.floor(Math.random() * 20) - 10
      
      return Math.max(0, Math.min(100, score))
    },
    
    calculateEnterpriseMatchScore(enterprise, policy) {
      let score = 50 // 基础分
      
      // 企业规模匹配
      if (policy.category === '财税政策' && enterprise.size.includes('小')) {
        score += 20
      }
      
      // 行业匹配
      if (policy.category === '产业政策' && enterprise.industry === '制造业') {
        score += 25
      }
      
      if (policy.category === '科技政策' && enterprise.industry === '信息技术') {
        score += 25
      }
      
      // 偏好匹配
      if (this.enterprisePreferences.categories.includes(policy.category)) {
        score += 15
      }
      
      return Math.max(0, Math.min(100, score))
    },
    
    calculateExpectedBenefit(enterprise, policy) {
      const baseAmount = enterprise.revenue * 0.05 // 基础按营业额5%计算
      
      if (policy.category === '财税政策') {
        return Math.floor(baseAmount * 1.5)
      } else if (policy.category === '科技政策') {
        return Math.floor(baseAmount * 2)
      }
      
      return Math.floor(baseAmount)
    },
    
    getPolicyMatchReasons(policy, enterprise) {
      const reasons = []
      
      if (policy.category === '财税政策' && enterprise.size.includes('小')) {
        reasons.push('小微企业优惠')
      }
      
      if (enterprise.industry === '制造业') {
        reasons.push('制造业扶持')
      }
      
      if (enterprise.industry === '信息技术') {
        reasons.push('科技创新支持')
      }
      
      reasons.push('地区适用', '规模匹配')
      
      return reasons.slice(0, 3)
    },
    
    getEnterpriseMatchPoints(enterprise, policy) {
      const points = []
      
      if (enterprise.size.includes('小') && policy.category === '财税政策') {
        points.push('小微企业扶持')
      }
      
      if (enterprise.industry === '制造业' && policy.category === '产业政策') {
        points.push('制造业转型')
      }
      
      if (enterprise.industry === '信息技术') {
        points.push('科技创新')
      }
      
      points.push('税收优惠', '资金补贴')
      
      return points.slice(0, 3)
    },
    
    getApplicationDifficulty(policy) {
      const difficulties = ['简单', '中等', '复杂']
      return difficulties[Math.floor(Math.random() * difficulties.length)]
    },
    
    getMatchLevelClass(score) {
      if (score >= 80) {
        return 'px-2 py-1 bg-green-500/20 text-green-300 rounded text-xs'
      } else if (score >= 60) {
        return 'px-2 py-1 bg-yellow-500/20 text-yellow-300 rounded text-xs'
      } else {
        return 'px-2 py-1 bg-red-500/20 text-red-300 rounded text-xs'
      }
    },
    
    getSizeValue(size) {
      const sizeMap = {
        '大型企业': 4,
        '中型企业': 3,
        '小型企业': 2,
        '微型企业': 1
      }
      return sizeMap[size] || 0
    },
    
    getDifficultyValue(difficulty) {
      const difficultyMap = {
        '简单': 1,
        '中等': 2,
        '复杂': 3
      }
      return difficultyMap[difficulty] || 2
    }
  }
}
</script> 